home *** CD-ROM | disk | FTP | other *** search
- Path: newshub.cts.com!usenet
- From: lboard@cts.com (Larry Board)
- Newsgroups: comp.lang.c++
- Subject: Re: What is referencing good for?
- Date: Thu, 29 Feb 1996 05:42:34 GMT
- Organization: CTS Network Services
- Message-ID: <313539c9.4835024@news2.cts.com>
- References: <4goojd$a9g@wintermute.ecs.fullerton.edu>
- NNTP-Posting-Host: lboard.cts.com
-
- On 25 Feb 1996 04:29:33 GMT, grosin@titan.fullerton.edu (Gil Rosin)
- wrote:
-
- >I've been playing with referencing all day, and I can not find one use for it
- >that I can not do with pointers. What is referencing good for? I know about
- >reference parameters and I know about reference functions.
-
- >Can someone give me a REAL world example of where I would use referencing
- >perhaps somewhere that I can not use pointers?
-
-
- I ran across a slick use for references this morning while reading the
- Microsoft iostream class library reference. It basically described
- how you could write your own manipulators using references.
-
- The code below is a modification of the example they gave. It
- basically creates two new manipulators called bold and normal.
- Assuming that ansi.sys is loaded, bold sets the display to high
- intensity, while normal turns it off.
-
-
- ------------------------------------------------------
- #include <iostream.h>
-
- ostream& bold(ostream& os)
- {
- return os << '\033' << "[1m";
- }
-
- ostream& normal(ostream& os)
- {
- return os << '\033' << "[0m";
- }
-
- main()
- {
- cout << "normal text " << bold << "bold text" << normal << "\n";
- return(0);
- }
- ------------------------------------------------------
-
-
-